package net.tv90.volunteerserveradmin.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.tv90.volunteerserveradmin.constant.RoleConstant;
import net.tv90.volunteerserveradmin.model.domain.OperationLog;
import net.tv90.volunteerserveradmin.model.dto.OperationLogQueryDTO;
import net.tv90.volunteerserveradmin.model.vo.OperationLogVO;
import net.tv90.volunteerserveradmin.utils.entity.PageResult;
import net.tv90.volunteerserveradmin.service.OperationLogService;
import net.tv90.volunteerserveradmin.utils.entity.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@CrossOrigin
@RestController
@RequestMapping("log")
@Tag(name = "日志管理接口")
public class OperationLogController {

    @Resource
    private OperationLogService operationLogService;

    @GetMapping("/all")
    @SaCheckRole(RoleConstant.ADMIN)
    @Operation(summary = "获取所有日志", description = "获取所有日志信息")
    public Result<List<OperationLog>> getAllLog() {
        return Result.success(operationLogService.getAllLogs());
    }

    @PostMapping("/query")
    @SaCheckRole(RoleConstant.ADMIN)
    @Operation(summary = "查询日志信息", description = "复杂查询日志信息")
    public Result<PageResult<OperationLogVO>> queryLog(@RequestBody OperationLogQueryDTO dto) {
        return Result.success(operationLogService.queryLogs(dto));
    }

    @GetMapping("/{id}")
    @SaCheckRole(RoleConstant.ADMIN)
    @Operation(summary = "获取日志信息", description = "根据日志ID获取日志详细信息")
    public Result<OperationLogVO> getOperationLogById(@PathVariable Long id) {
        return Result.success(operationLogService.findById(id));
    }
}
